package com.darrenchan.leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-03-08 13:35
 */
public class Q1269 {
    public int numWays(int steps, int arrLen) {
        int level = 0, res = 0;
        Queue<Integer> queue = new LinkedList<>();
        queue.add(0);

        while(!queue.isEmpty()) {
            int size = queue.size();
            level++;
            for (int i = 0; i < size; i++) {
                Integer poll = queue.poll();
                if(poll == 0 && level == steps) {
                    res++;
                }

                queue.add(poll);
                if(poll - 1 >= 0) {
                    queue.add(poll - 1);
                }
                if(poll + 1 < arrLen) {
                    queue.add(poll + 1);
                }
            }
        }

        return res;
    }
}
